﻿
@{
    Layout = null;
}
<div class="bjui-pageContent">
    <table class="table table-bordered" id="datagrid-Menu@(Request.QueryString["_"])" data-toggle="datagrid"></table>
</div>
<script type="text/javascript">
    var menuGrid@(Request.QueryString["_"]) = $('#datagrid-Menu@(Request.QueryString["_"])');
    menuGrid@(Request.QueryString["_"]).datagrid({
        width: '100%',
        height: '100%',
        showToolbar: true,
        toolbarItem: 'refresh,save,cancel',
        local: 'local',
        dataUrl: '/Menu/GetMenuTree',
        inlineEditMult: false,
        afterSave: saveCallBack,
        editUrl: '/Menu/MenuUpsert',
        delUrl: '/Menu/DelMenu',
        delPK: 'id',
        isTree: 'name',
        addLocation: 'last',
        showCheckboxcol: false,
        filterMult: false,
        filterThead: true,
        fieldSortable: false,
        columnMenu: false,
        paging: false,
        treeOptions: {
            expandAll: false,
            add: true,
            simpleData: true,
            keys: {
                parentKey: 'pid'
            }
        },
        columns: [
            { name: 'name', align: 'center', width: 250, label: '菜单项', rule: 'required' },
            { name: 'id', align: 'center', width: 250, label: 'ID' },
            { name: 'icon', align: 'center', width: 350, label: '图标' },
            { name: 'url', align: 'left', width: 350, label: 'url' }, {
                name: 'pid', align: 'center', width: 250, label: '父ID', rule: 'required'//, attrs: { readonly: "readonly" }
            },
            { name: 'enabled', align: 'center', width: 150, label: '是否禁用', rule: 'required', type: 'select', items: [{ '1': '启用' }, { '0': '禁用' }] },
            { name: 'score', align: 'center', width: 200, label: '排序', rule: 'required;integer' },
            { label: '操作', align: 'center', width: 200, render: datagrid_tree_operation },
        ]
    });


    function datagrid_tree_operation() {
        var html = '<button type="button" class="btn-green" data-toggle="edit.datagrid.tr">编辑</button>'
            + '<button type="button" class="btn-red" data-toggle="del.datagrid.tr">删除</button>';
        return html
    }

    function refreshGri() {
        menuGrid@(Request.QueryString["_"]).datagrid('filter', {});
        //menuGrid.datagrid('filter', { "clearOldPostData": true });
    }
    function btnClearSearch() {
        return $("<button type='button' class='btn-default btn' onclick='refreshGri()'>清空查询</button>");
    }

    function saveCallBack($trs, datas) {
        menuGrid@(Request.QueryString["_"]).datagrid('refresh', false);
    }


</script>
